<?php
class User_model extends Base_Model
{
    const TABLE = 'mod_user';
    const INFOTABLE = 'mod_user_info';

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    /**
     * 创建用户
     * @param $data
     * @return bool|int
     */
    public function createUser($data)
    {

        if($this->db->insert(self::TABLE, $data)){
            return $this->db->insert_id();
        } else {
            return false;
        }
    }

    /**
     * 创建用户信息
     * @param $data
     * @return bool|int
     */
    public function createUserInfo($data)
    {

        if($this->db->insert(self::INFOTABLE, $data)){
            return $this->db->insert_id();
        } else {
            return false;
        }
    }

    /**
     * 修改用户信息
     * @param $data
     * @param $where
     * @return bool
     */
    public function editUser($data, $where)
    {
        return $this->db->update(self::TABLE, $data, $where);
    }

    /**
     * 获取用户信息
     * @param $where
     * @return mixed
     */
    function getUser($where, $data = '*')
    {
        $query = $this->db->select($data)->get_where(self::TABLE, $where);
        return $query->row_array();
    }
    /**
     * 批量获取用户信息
     * @param $where
     * @return mixed
     */
    function getBatchUsers($where, $data = '*')
    {
        $query = $this->db->select($data)->get_where(self::TABLE, $where);
        return $query->result_array();
    }

    /**
     * 获取用户所有信息
     *
     * @param $where
     * @return array
     */
    function getUserAll($where)
    {
        return $this->db->get_where(self::TABLE, $where)->row_array();
    }
}